package appinventor.ai_Ryan489.BBYM;

import android.app.Activity;
import android.content.Context;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class paymentCalc extends Activity
{
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	      
	     setContentView(R.layout.paymentcalc);
	     
	   
	     
	 	this.calcButton = (Button)this.findViewById(R.id.buttoncalcpayments);
		  this.calcButton.setOnClickListener(new OnClickListener() {
		    public void onClick(View v) {
		    	
		      doCalc();
		      
		    }
		  });
		   
}
		  private Button calcButton;
	public void doCalc()
	{
		//get the sale amount
		EditText saleamt;
    	saleamt = (EditText) findViewById(R.id.editSale);
    	    	int saleAmount; 
    	    	saleAmount = Integer.parseInt(saleamt.getText().toString());
    	    	
    	
    	//get the months
    	EditText months;
    	months = (EditText) findViewById(R.id.editMonths);
    	int manyMonths;
    	manyMonths = Integer.parseInt(months.getText().toString());
    	
    	int result;
    	result = (saleAmount / manyMonths);
    	String finalResult = Integer.toString(result);
    	
    	Context context = getApplicationContext();
    	CharSequence text = "Payment is: " + "$" + finalResult + " Per month.";
    	int duration = Toast.LENGTH_LONG;

    	Toast toast = Toast.makeText(context, text, duration);
    	toast.show();
    	
    	
    	
		
    	
	}
}